﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Check is prime</title>
    <link href="styles/js-console.css" rel="stylesheet" />
    <script src="scripts/isValidInput.js"></script>
</head>
<body>
    <label for="input">Enter positive integer number:</label>
    <input type="text" id="input" />
    <button onclick="IsPrime()">Check is prime</button>
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>
    <script>
        //Write an expression that checks if given positive integer number n (n ≤ 100) is prime. E.g. 37 is prime.
        function IsPrime() {
            var number = parseInt(document.getElementById("input").value);
            if (isValidInputNumber(number) && number >= 2 && number <= 100) {
                var isPrime = true;
                for (var i = 2; i < parseInt(Math.ceil(number)) ; i++) {
                    if (number % i == 0) {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime) {
                    jsConsole.writeLine("Number is prime.");
                }
                else {
                    jsConsole.writeLine("Number is NOT prime.");
                }
            }
            else {
                jsConsole.writeLine("Enter valid integer number [2 <= number <= 100].");
            }
        }

    </script>
</body>
</html>
